import request from '@/utils/request'
import {
  LOAD_DATA
} from './actions'

export default {
  namespaced: false,
  state: {
    name: 'app',
    testData: {}
  },
  getters: {},
  mutations: {
    [LOAD_DATA] (state, { data } = {}) {
      console.log('LOAD_DATA', data)
      state.testData = data
    }
  },
  actions: {
    async [LOAD_DATA] ({ commit }, params) {
      // https://api.coindesk.com/v1/bpi/currentprice.json
      try {
        const res = await request({
          url: 'v1/bpi/currentprice.json',
          method: 'get',
          data: { a: 1 }
        })
        // await request.post('v1/bpi/currentprice.json', { a: 1 })
        // await request.get('v1/bpi/currentprice.json', { params: { a: 1 } })
        if (res && res.data) {
          commit(LOAD_DATA, { data: res.data })
        }
      } catch (error) {
        console.error('LOAD_DATA', error)
      }
    }
  }
}
